package com.ate.lib_core.http.product;

import com.ate.lib_core.http.interceptor.TokenInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author Ate
 * @description:
 * @date :2020/12/10 11:13
 */
public class HttpRetrofitNetworkImpl implements IRetrofitProduct {
    Retrofit mRetrofit = null;

    @Override
    public void create() {
        OkHttpClient builder = new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor()
                        .setLevel(HttpLoggingInterceptor.Level.BODY))
                        .addInterceptor(new TokenInterceptor())
                        .connectTimeout(1, TimeUnit.MINUTES)
                        .readTimeout(1,TimeUnit.MINUTES)
                        .writeTimeout(1,TimeUnit.MINUTES)
                        .build();

        mRetrofit = new Retrofit.Builder()
                .baseUrl("http://39.98.153.96:8082/")
                .client(builder)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public Retrofit getRetrofit() {
        if (mRetrofit==null){
            create();
        }
        return mRetrofit;
    }
}
